package com.aurora.source.center.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aurora.source.R;
import com.aurora.source.base.BaseRecyclerAdapter;
import com.aurora.source.base.CommonHolder;
import com.aurora.source.center.bean.OprationRecoredBean;

import butterknife.BindView;

/**
 * @author: ww
 * @description:流程操作记录
 * @date: 2018/9/7
 */
public class OprationRecoredAdapter extends BaseRecyclerAdapter<OprationRecoredBean> {
    OnSeeRecoredClickListener onSeeRecoredClickListener;
    OnNewRecoredClickListener onNewRecoredClickListener;

    public void setOnSeeRecoredClickListener(OnSeeRecoredClickListener onSeeRecoredClickListener) {
        this.onSeeRecoredClickListener = onSeeRecoredClickListener;
    }

    public void setOnNewRecoredClickListener(OnNewRecoredClickListener onNewRecoredClickListener) {
        this.onNewRecoredClickListener = onNewRecoredClickListener;
    }

    @Override
    public CommonHolder<OprationRecoredBean> setViewHolder(ViewGroup parent) {
        return new MyHolder(parent.getContext(), parent);
    }

    public interface OnSeeRecoredClickListener{
        void onSeeClick(int position,OprationRecoredBean data);
    }

    public interface OnNewRecoredClickListener{
        void onNewClick(int position,OprationRecoredBean data);
    }

    class MyHolder extends CommonHolder<OprationRecoredBean> {


        @BindView(R.id.tv_batch_name)
        TextView tvBatchName;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.ll_recored)
        LinearLayout llRecored;
        @BindView(R.id.ll_see_recored)
        LinearLayout llSeeRecored;
        @BindView(R.id.ll_add_recored)
        LinearLayout llAddRecored;

        public MyHolder(Context context, ViewGroup root) {
            super(context, root, R.layout.item_opration_recored);
        }

        @Override
        public void bindData(final OprationRecoredBean oprationRecoredBean, final int positon) {
            if(oprationRecoredBean.getIsWinding().equals("Y")){ //上链
                llAddRecored.setVisibility(View.GONE);
            }else {
                llAddRecored.setVisibility(View.VISIBLE);
            }

            llAddRecored.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onNewRecoredClickListener.onNewClick(positon,oprationRecoredBean);
                }
            });

            tvName.setText(oprationRecoredBean.getImplementedUser());
            tvTime.setText(oprationRecoredBean.getCreateTime());
            tvBatchName.setText(oprationRecoredBean.getRemark());
            tvTitle.setText(oprationRecoredBean.getParentBatchName());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onClick(positon,oprationRecoredBean);
                }
            });
        }
    }
}
